package ar.edu.sovietrussia.customcomponents.librarianstuff.returncopy;

import org.apache.wicket.markup.html.basic.Label;
import org.apache.wicket.markup.html.form.Button;
import org.apache.wicket.markup.html.form.Form;
import org.apache.wicket.markup.html.form.RequiredTextField;
import org.apache.wicket.markup.html.panel.Panel;
import org.apache.wicket.model.Model;

/**
 * Has a Form with an Integer input representing a copy's code.
 */
public class ReturnCopyPanel extends Panel {

    private static final long serialVersionUID = 1L;

    public ReturnCopyPanel(final String id) {
        super(id);
        this.addComponents();
    }

    private void addComponents() {
        this.addForm("form");
    }

    private void addForm(final String id) {
        Button submitButton = new Button("submit", new Model<String>("Return copy"));

        final RequiredTextField<String> input = new RequiredTextField<String>("code", new Model());

        Form form = new Form(id) {
            private static final long serialVersionUID = 1L;

            @Override
            protected void onSubmit() {
                ReturnCopyPanel.this.onSubmit(Integer.parseInt(input.getModelObject()));
            }
        };

        form.add(new Label("code_label", "Copy code:"));
        form.add(input);
        form.add(submitButton);
        this.add(form);
    }

    public void onSubmit(final int code) {
        // redefinir arriba
    }

}
